<template>
  <div class="details">
    <div class="details-title flex items-center" @click="isShow = !isShow">
      <el-icon class="mr-8px"><ArrowDown /></el-icon>基本信息
    </div>
    <div class="details-content flex flex-wrap" v-if="isShow">
      <div class="w-50% flex mb-18px">
        <div class="label">客户名称</div>
        <div class="content">{{ CustomerValue.name }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">客户来源</div>
        <div class="content"
          ><dict-tag :type="DICT_TYPE.CRM_CUSTOMER_SOURCE" :value="CustomerValue.source"
        /></div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">手机</div>
        <div class="content">
          <el-link v-if="CustomerValue.mobile" @click="onCall(CustomerValue, CustomerValue.mobile)"
            >{{ CustomerValue.encryptMobile }} <Icon class="ml-5px" icon="ep:phone" />
          </el-link>
        </div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">电话</div>
        <div class="content">
          <el-link
            v-if="CustomerValue.telephone"
            @click="onCall(CustomerValue, CustomerValue.telephone)"
            >{{ CustomerValue.encryptTelephone }} <Icon class="ml-5px" icon="ep:phone" />
          </el-link>
        </div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">邮箱</div>
        <div class="content">{{ CustomerValue.email }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">地址</div>
        <div class="content"> {{ CustomerValue.areaName }} {{ CustomerValue.detailAddress }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">QQ</div>
        <div class="content">{{ CustomerValue.qq }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">微信</div>
        <div class="content">{{ CustomerValue.wechat }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">客户行业</div>
        <div class="content">
          <dict-tag :type="DICT_TYPE.CRM_CUSTOMER_INDUSTRY" :value="CustomerValue.industryId"
        /></div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">客户级别</div>
        <div class="content"
          ><el-tag
            v-if="CustomerValue.levelRespVO"
            :disable-transitions="false"
            :style="{
              background: CustomerValue.levelRespVO.bgColor,
              color: CustomerValue.levelRespVO.textColor,
              marginRight: '10px',
              border: 'none',
              cursor: 'pointer',
              paddingRight: '9px'
            }"
          >
            {{ CustomerValue.levelRespVO.name }}
          </el-tag></div
        >
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">下次联系时间</div>
        <div class="content"> {{ formatDate(CustomerValue.contactNextTime) }}</div>
      </div>
      <div class="w-50% flex mb-18px">
        <div class="label">备注</div>
        <div class="content">{{ CustomerValue.remark }}</div>
      </div>
      <div class="w-50% flex mb-18px" :key="item.id" v-for="item in CustomerValue.detailFiled">
        <div class="label">{{ item.name }}</div>
        <div class="content">{{
          item.fieldType == 'time'
            ? formatDate(CustomerValue[item.fieldName])
            : CustomerValue[item.fieldName]
        }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ArrowDown } from '@element-plus/icons-vue'
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import WebPhone from '@/hooks/web/useCall'
import { useSoftPhoneStore } from '@/store/modules/softPhone'
import { usePhoneStore } from '@/store/modules/phone'
import { emitter } from '@/utils/eventBus.ts'

const useStore = usePhoneStore()
const useSoftPhone = useSoftPhoneStore()
const isShow = ref(true)
const props = defineProps({
  CustomerValue: Object
})
const onCall = (row, callee) => {
  emitter.emit('simCall', {
    callee,
    source: 'customer',
    sourceId: row.id
  })
  emitter.emit('userCallCallee', callee)
}
</script>

<style lang="scss" scoped>
.details {
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px #172b4d1a;
  margin: 0 8px;
  margin-bottom: 20px;
  .details-title {
    font-size: 14px;
    color: #172b4d;
    cursor: pointer;
    padding: 16px;
  }
}
.label {
  width: 88px;
  line-height: 32px;
  text-overflow: ellipsis;
  text-align: right;
  color: #42526e;
  font-size: 14px;
  padding-right: 12px;
}
.content {
  width: calc(100% - 126px);
  margin-right: 12px;
  padding: 0 6px;
  min-height: 32px;
  line-height: 32px;
  color: #172b4d;
  font-size: 14px;
  background-color: #ebecf0;
  border: 1px solid #dfe1e6;
  border-radius: 4px;
  overflow-wrap: break-word;
}
.shark {
  flex-shrink: 0;
}
</style>
